<{include file="public/header" /}>
<body style="background-color: #F2F2F2;">

<div style="padding: 10px; background-color: #F2F2F2;padding-bottom: 50px">
  <form class="layui-form layui-form-pane" lay-filter="editform">
    <div class="layui-card">
      <!-- <div class="layui-card-header">请毕业生如实认真填写</div> -->
        <div class="layui-card-body">
            
          <div class="layui-form-item">
                
              <{volist name="teachers" id="vo"}>
                <div class="layui-inline">
                  <div class="layui-input-inline" style="width: 80px;">
                    <input type="checkbox" name="tids[]" title="<{$vo.truename}>" lay-skin="primary" value="<{$vo.tid}>" <{in name="vo.tid" value="$allocate|array_keys"}>checked<{/in}>>
                  </div>
                  <div class="layui-input-inline" style="width: 80px;text-align: center;">
                    <input type="number" name="allocate[<{$vo.tid}>]" placeholder="" lay-verify="mynumber" autocomplete="off" class="layui-input" value="<{$allocate[$vo.tid][0]|default=''}>" min = 0>
                  </div>
                  <div class="layui-form-mid">份</div>
                </div>
              <{/volist}>
          </div>
          
          <!-- <div class="layui-form-item">
            <label class="layui-form-label">允许班级：</label>
            <div class="layui-input-block">
              <input type="checkbox" name="class[]" title="写作" lay-skin="primary" checked>
              <input type="checkbox" name="class[]" title="写作" lay-skin="primary" checked>
            </div>
          </div> -->
          <div class="layui-form-item">
            <input type="hidden" name="eid"  value="<{$eid}>">
          </div> 
          <hr>
          <p style="text-align: center;color: #009688;">已分配试题<span id="total" style="color: #FF5722;font-size: 25px;"><{$allocate|array_first_sum|default=0}></span>份，共<span style="color: #FF5722;font-size: 25px;"><{$total}></span>份
          </p>
      </div>
     </div>
    <div class="layui-card" style="padding-top: 10px;position:absolute;bottom:10px;width:96%;">
      <!-- <div class="layui-card-header">卡片面板</div> -->
      <div class="layui-card-body">

        <!-- <div class="layui-form-item">
            <input type="hidden" name="eid"  value="<{$eid}>">
        </div> -->
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit="" type = "button" lay-filter="demo2" id="demo2">提交</button>
        </div>
      </div>
    </div>
  </form>
</div>



<script>

layui.use(['form','element','layer','jquery'], function(){
  var $ = layui.$
  ,form = layui.form,element = layui.element,layer = layui.layer;
  //----------上面引入layui下面开始业务，分割一下-----------------//
  form.verify({
  mynumber: function(value, item){ //value：表单的值、item：表单的DOM对象
    // if(!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)){
    //   return '用户名不能有特殊字符';
    // }
    var che=$(item).parent().prev().children('input').prop("checked");
    if (che===true && value==''){
      return '请分配教师任务';
    }
    //console.log($(item).parent().prev().children('input').prop("checked"));
  }
});
$("input[type='number']").bind('input propertychange',function(){ 
    var sum=0; 
    $("input[type='number']").each(function(){ 
      var r = /^-?\d+$/ ;　//正整数 
      if($(this).val() !=''&&!r.test($(this).val())){ 
       $(this).val("");  //正则表达式不匹配置空 
      }else if($(this).val() !=''){ 
       sum+=parseInt($(this).val()); 
      } 
      //document.getElementById("add").value=sum; 
      var total='<{$total}>';
      $('#total').html(sum);if (sum>total) {layer.alert('分配数量大于总数！');}
      }); 
    }); 
   //监听表单提交
  form.on('submit(demo2)', function(data){
    // layer.alert(JSON.stringify(data.field), {
    //   title: '最终的提交信息'
    // })
        layer.confirm('确定提交?', {btn: ['提交','取消'],icon: 3, title:'提示'}
        ,function(index){
          //do something
            $.post("<{:url('do_allocate')}>",data.field,function(data,status){
              //alert(data);
              //alert(JSON.stringify(data));
              //console.log(data);
              if(data===1){
                layer.msg('提交成功!',{icon: 6,time:1000},function(index){
                   x_father_close();
                   //parent.location.reload();
                });
                
              }else{
                layer.alert(data,function(index){
                  layer.close(index);
                }); 
              }
           })
          
        }
      );
     
    
  });
  
});
//删除 预览图片需要加载jquery    
// function deleteImg(obj){
//             obj.parent('.imglist').remove();
//             //var aa=$('div');
//             //aa.remove('#imglist');
// }

</script>


</body>
</html>